package net.oktaeder.office.model;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Represents time in the office. Consists of a year, a month and a week
 * 
 * @author tuukka
 *
 */
public class Time {

	private static Log log = LogFactory.getLog(Model.class);
	
	private int year;
	private int month;
	private int week;
	
	public Time() {
		log.trace("Creating an instance, default constructor");
	}
	
	public Time(int year, int month, int week) {
		super();
		log.trace("Creating an instance");
		this.year = year;
		this.month = month;
		this.week = week;
	}
	
	public int getMonth() {
		return month;
	}
	
	public void setMonth(int month) {
		if ((month > 12) || (month < 1)) {
			log.warn("Setting a suspicious month: " + month);
		}
		this.month = month;
	}
	
	public int getWeek() {
		return week;
	}
	
	public void setWeek(int week) {
		if ((week > 4) || (week < 1)) {
			log.warn("Setting a suspicious week: " + week);
		}
		this.week = week;
	}
	
	public int getYear() {
		return year;
	}
	
	public void setYear(int year) {
		if ((year < 1)) {
			log.warn("Setting a suspicious year: " + year);
		}
		this.year = year;
	}
	
	/**
	 * Advances time by one week, taking care of changing months and years as needed
	 *
	 */
	public void advance() {
		week = week + 1;
		if (week > 4) {
			week = 1;
			month = month + 1;
			if (month > 12) {
				month = 1;
				year = year + 1;
			}
		}
	}
}
